<template>
  <div class="search-result">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="(article,index) in list" :key="index" :title="article.title" />
    </van-list>
  </div>
</template>

<script>
import { getSearchResults } from "@/API/search";
export default {
  name: "SearchResult",
  props: {
    searchText: {
      type: String,
      required: true,
    }
  },
   data() {
    return {
      list: [],
      loading: false,
      finished: false,//加载结束的文字提示
      page:1,
      perPage:10
    };
  },
  methods: {
   async onLoad() {
     const { data } = await getSearchResults({
       page:this.page,   //页码
       per_page:this.per_page,  //每页大小
       q :this.searchText  //搜索的字符
     })
     const {results} =data.data
     this.list.push(...results)

     this.loading=false
     if(results.length){
       this.page++
     }else{
       this.finished = true
     }
    }
  }
};
</script>

<style>
</style>